home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / OLEWINDO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  48.9 KB  |  2,332 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   10.22  $
  6. //
  7. // Implementation of TOleWindow. Window class that supports OLE 2
  8. // container & server using OCF TOcView & TOcRemView
  9. //----------------------------------------------------------------------------
  10. #define INC_OLE2
  11. #include <owl/pch.h>
  12. #if !defined(OWL_WINDOW_H)
  13. # include <owl/window.h>
  14. #endif
  15. #if !defined(OWL_GDIOBJEC_H)
  16. # include <owl/gdiobjec.h>
  17. #endif
  18. #if !defined(OWL_SCROLLER_H)
  19. # include <owl/scroller.h>
  20. #endif
  21. #if !defined(OCF_OCDOC_H)
  22. # include <ocf/ocdoc.h>
  23. #endif
  24. #if !defined(OCF_OCVIEW_H)
  25. # include <ocf/ocview.h>
  26. #endif
  27. #if !defined(OCF_OCCTRL_H) && defined(BI_PLAT_WIN32)
  28. # include <ocf/occtrl.h>
  29. #endif
  30. #if !defined(OWL_OLEFRAME_H)
  31. # include <owl/oleframe.h>
  32. #endif
  33. #if !defined(OWL_OLEWINDO_H)
  34. # include <owl/olewindo.h>
  35. #endif
  36. #if !defined(WINSYS_UIMETRIC_H)
  37. # include <winsys/uimetric.h>
  38. #endif
  39. #if !defined(OWL_EDIT_RH)
  40. # include <owl/edit.rh>
  41. #endif
  42. #if !defined(OWL_DOCVIEW_RH)
  43. # include <owl/docview.rh>
  44. #endif
  45. #if !defined(OWL_OLEVIEW_RH)
  46. # include <owl/oleview.rh>
  47. #endif
  48.  
  49. OWL_DIAGINFO;
  50. DIAG_DECLARE_GROUP(OwlCmd);
  51.  
  52.  
  53.  
  54. //----------------------------------------------------------------------------
  55. // TOleClientDC
  56. //
  57.  
  58. //
  59. //
  60. //
  61. TOleClientDC::TOleClientDC(TOleWindow& win, bool scale)
  62. :
  63.   TClientDC(win)
  64. {
  65.   win.SetupDC(*this, scale);
  66. }
  67.  
  68. //----------------------------------------------------------------------------
  69. // TOleWindow
  70. //
  71.  
  72. DEFINE_RESPONSE_TABLE1(TOleWindow, TWindow)
  73.   EV_WM_PAINT,
  74.   EV_WM_LBUTTONDOWN,
  75.   EV_WM_RBUTTONDOWN,
  76.   EV_WM_LBUTTONDBLCLK,
  77.   EV_WM_MOUSEMOVE,
  78.   EV_WM_LBUTTONUP,
  79.   EV_WM_SIZE,
  80.   EV_WM_MDIACTIVATE,
  81.   EV_WM_MOUSEACTIVATE,
  82.   EV_WM_SETFOCUS,
  83.   EV_WM_SETCURSOR,
  84.   EV_WM_DROPFILES,
  85.   EV_WM_VSCROLL,
  86.   EV_WM_HSCROLL,
  87.   EV_WM_MENUSELECT,
  88.  
  89.   EV_COMMAND_ENABLE(CM_FILECLOSE, CeFileClose),
  90.  
  91.   EV_COMMAND(CM_EDITDELETE, CmEditDelete),
  92.   EV_COMMAND_ENABLE(CM_EDITDELETE, CeEditDelete),
  93.   EV_COMMAND(CM_EDITCUT, CmEditCut),
  94.   EV_COMMAND_ENABLE(CM_EDITCUT, CeEditCut),
  95.   EV_COMMAND(CM_EDITCOPY, CmEditCopy),
  96.   EV_COMMAND_ENABLE(CM_EDITCOPY, CeEditCopy),
  97.   EV_COMMAND(CM_EDITPASTE, CmEditPaste),
  98.   EV_COMMAND_ENABLE(CM_EDITPASTE, CeEditPaste),
  99.   EV_COMMAND(CM_EDITPASTESPECIAL, CmEditPasteSpecial),
  100.   EV_COMMAND_ENABLE(CM_EDITPASTESPECIAL, CeEditPasteSpecial),
  101.   EV_COMMAND(CM_EDITPASTELINK, CmEditPasteLink),
  102.   EV_COMMAND_ENABLE(CM_EDITPASTELINK, CeEditPasteLink),
  103.   EV_COMMAND(CM_EDITINSERTOBJECT, CmEditInsertObject),
  104.  
  105. #if defined(BI_PLAT_WIN32)
  106.   EV_COMMAND(CM_EDITINSERTCONTROL, CmEditInsertControl),
  107. #endif
  108.  
  109.   EV_COMMAND_ENABLE(CM_EDITINSERTOBJECT, CeEditInsertObject),
  110.  
  111. #if defined(BI_PLAT_WIN32)
  112.   EV_COMMAND_ENABLE(CM_EDITINSERTCONTROL, CeEditInsertControl),
  113. #endif
  114.  
  115.   EV_COMMAND_ENABLE(CM_EDITLINKS, CeEditLinks),
  116.   EV_COMMAND(CM_EDITLINKS, CmEditLinks),
  117.   EV_COMMAND_ENABLE(CM_EDITOBJECT, CeEditObject),
  118.   EV_COMMAND_ENABLE(CM_EDITCONVERT, CeEditConvert),
  119.   EV_COMMAND(CM_EDITCONVERT, CmEditConvert),
  120.   EV_COMMAND_ENABLE(CM_EDITSHOWOBJECTS, CeEditShowObjects),
  121.   EV_COMMAND(CM_EDITSHOWOBJECTS, CmEditShowObjects),
  122.  
  123.   EV_MESSAGE(WM_OCEVENT, EvOcEvent),
  124.  
  125.   // Container specific messages
  126.   //
  127.   EV_OC_VIEWPARTINVALID,
  128.   EV_OC_VIEWTITLE,
  129.   EV_OC_VIEWSETTITLE,
  130.   EV_OC_VIEWBORDERSPACEREQ,
  131.   EV_OC_VIEWBORDERSPACESET,
  132.   EV_OC_VIEWDROP,
  133.   EV_OC_VIEWDRAG,
  134.   EV_OC_VIEWSCROLL,
  135.   EV_OC_VIEWGETSCALE,
  136.   EV_OC_VIEWGETSITERECT,
  137.   EV_OC_VIEWSETSITERECT,
  138.   EV_OC_VIEWPARTACTIVATE,
  139.   EV_OC_VIEWPASTEOBJECT,
  140.  
  141.   // Server specific messages
  142.   //
  143.   EV_OC_VIEWPAINT,
  144.   EV_OC_VIEWSAVEPART,
  145.   EV_OC_VIEWLOADPART,
  146.   EV_OC_VIEWINSMENUS,
  147.   EV_OC_VIEWSHOWTOOLS,
  148.   EV_OC_VIEWGETPALETTE,
  149.   EV_OC_VIEWCLIPDATA,
  150.   EV_OC_VIEWSETDATA,
  151.   EV_OC_VIEWCLOSE,
  152.   EV_OC_VIEWPARTSIZE,
  153.   EV_OC_VIEWOPENDOC,
  154.   EV_OC_VIEWATTACHWINDOW,
  155.   EV_OC_VIEWSETSCALE,
  156.   EV_OC_VIEWGETITEMNAME,
  157.   EV_OC_VIEWSETLINK,
  158.   EV_OC_VIEWBREAKLINK,
  159.   EV_OC_VIEWDOVERB,
  160.  
  161. #if defined(BI_PLAT_WIN32)
  162.   // Ambient properties
  163.   //
  164.   EV_OC_AMBIENT_GETBACKCOLOR,
  165.   EV_OC_AMBIENT_GETFORECOLOR,
  166.   EV_OC_AMBIENT_GETLOCALEID,
  167.   EV_OC_AMBIENT_GETTEXTALIGN,
  168.   EV_OC_AMBIENT_GETMESSAGEREFLECT,
  169.   EV_OC_AMBIENT_GETUSERMODE,
  170.   EV_OC_AMBIENT_GETUIDEAD,
  171.   EV_OC_AMBIENT_GETSHOWGRABHANDLES,
  172.   EV_OC_AMBIENT_GETSHOWHATCHING,
  173.   EV_OC_AMBIENT_GETDISPLAYASDEFAULT,
  174.   EV_OC_AMBIENT_GETSUPPORTSMNEMONICS,
  175.   EV_OC_AMBIENT_GETDISPLAYNAME,
  176.   EV_OC_AMBIENT_GETSCALEUNITS,
  177.   EV_OC_AMBIENT_GETFONT,
  178.   EV_OC_AMBIENT_SETBACKCOLOR,
  179.   EV_OC_AMBIENT_SETFORECOLOR,
  180.   EV_OC_AMBIENT_SETLOCALEID,
  181.   EV_OC_AMBIENT_SETTEXTALIGN,
  182.   EV_OC_AMBIENT_SETMESSAGEREFLECT,
  183.   EV_OC_AMBIENT_SETUSERMODE,
  184.   EV_OC_AMBIENT_SETUIDEAD,
  185.   EV_OC_AMBIENT_SETSHOWGRABHANDLES,
  186.   EV_OC_AMBIENT_SETSHOWHATCHING,
  187.   EV_OC_AMBIENT_SETDISPLAYASDEFAULT,
  188.   EV_OC_AMBIENT_SETSUPPORTSMNEMONICS,
  189.   EV_OC_AMBIENT_SETDISPLAYNAME,
  190.   EV_OC_AMBIENT_SETSCALEUNITS,
  191.   EV_OC_AMBIENT_SETFONT,
  192.  
  193.   // Standard Events
  194.   //
  195.   EV_OC_CTRLEVENT_CLICK,
  196.   EV_OC_CTRLEVENT_DBLCLICK,
  197.  
  198.  
  199.   // Ctrl events
  200.   //
  201.   EV_OC_CTRLEVENT_CLICK,
  202.   EV_OC_CTRLEVENT_DBLCLICK,
  203.   EV_OC_CTRLEVENT_FOCUS,
  204.   EV_OC_CTRLEVENT_MOUSEDOWN,
  205.   EV_OC_CTRLEVENT_MOUSEMOVE,
  206.   EV_OC_CTRLEVENT_MOUSEUP,
  207.   EV_OC_CTRLEVENT_KEYDOWN,
  208.   EV_OC_CTRLEVENT_KEYUP,
  209.   EV_OC_CTRLEVENT_PROPERTYCHANGE,
  210.   EV_OC_CTRLEVENT_PROPERTYREQUESTEDIT,
  211.   EV_OC_CTRLEVENT_ERROREVENT,
  212.   EV_OC_CTRLEVENT_CUSTOMEVENT,
  213. #endif
  214.  
  215. END_RESPONSE_TABLE;
  216.  
  217. //
  218. //
  219. //
  220. TOleWindow::TOleWindow(TWindow* parent, TModule* module)
  221.            :TWindow(parent, 0, module), Pos(0, 0, 0, 0),
  222.             Remote(false), ShowObjects(false)
  223. {
  224.   // Initialize virtual base, in case the derived-most used default ctor
  225.   //
  226.   TWindow::Init(parent, 0, module);
  227.  
  228.   // Derived class will need to create a OcDocument object to hold the OLE
  229.   // parts that we create and a OcView to provide OLE services
  230.   //
  231.   OcApp  = 0;
  232.   OcDoc  = 0;
  233.   OcView = 0;
  234.  
  235.   Init();
  236. }
  237.  
  238. //
  239. //
  240. //
  241. void
  242. TOleWindow::Init()
  243. {
  244.   // Clip children to not paint on in-place servers, & clip siblings to not
  245.   // paint on floating tool palettes
  246.   //
  247.   Attr.Style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
  248.  
  249.   Attr.AccelTable = IDA_OLEVIEW;
  250.   DragHit   = TUIHandle::Outside;
  251.   DragPart  = 0;
  252.   DragDC    = 0;
  253.  
  254.   // Minimum part size
  255.   //
  256.   HDC dc = GetDC(0);
  257.   MinWidth  = GetDeviceCaps(dc, LOGPIXELSX) / 4;
  258.   MinHeight = GetDeviceCaps(dc, LOGPIXELSY) / 4;
  259.   ReleaseDC(0, dc);
  260.  
  261.   // Snag the OcApp from the TOleFrame object for quick reference
  262.   //
  263.   TOleFrame* olefr = TYPESAFE_DOWNCAST(GetApplication()->GetMainWindow(), TOleFrame);
  264.   CHECK(olefr);
  265.   OcApp = olefr->GetOcApp();
  266.   OcApp->AddRef();
  267. }
  268.  
  269. //
  270. //
  271. //
  272. TOleWindow::~TOleWindow()
  273. {
  274.   // Let the OC objects go. They will delete themselves when they can
  275.   // If it's a remote view, then the last release is called by the container.
  276.   //
  277.   if (OcDoc)
  278.     OcDoc->Close();           // close all the embedded parts first
  279.   if (OcView && !IsRemote()) {
  280.     OcView->ReleaseObject();  // use ReleaseObject here to tell it we are gone
  281.     OcView = 0;
  282.   }
  283.  
  284.   delete OcDoc;
  285.   if (OcApp) {
  286.     OcApp->Release();
  287.     OcApp = 0;
  288.   }
  289. }
  290.  
  291. //
  292. // Perform normal SetupWindow, plus let the OcView object know our HWND so that
  293. // it can talk to us.
  294. //
  295. void
  296. TOleWindow::SetupWindow()
  297. {
  298.   if (!OcView)
  299.     CreateOcView(0, false, 0);  // don't have much context by this time
  300.   CHECK(OcView);
  301.   TWindow::SetupWindow();
  302.   OcView->SetupWindow(*this, IsRemote());
  303. }
  304.  
  305. //
  306. // Called to perform the actual setting up of the OcView member
  307. // Derived class needs to construct the TOcView/TOcRemView here & return it
  308. //
  309. TOcView*
  310. TOleWindow::CreateOcView(TRegLink* link, bool isRemote, IUnknown* outer)
  311. {
  312.   if (!OcDoc)
  313.     OcDoc = new TOcDocument(*GetOcApp());
  314.  
  315.   if (!OcView) {
  316.     TRegList* regList = link ? &link->GetRegList() : 0;
  317.  
  318.     // Create a remote view on the server document if it embeded, else make a
  319.     // normal container view [capable of hosting OCXes or 'normal' servers]
  320.     //
  321.     if (isRemote)
  322.       OcView = new TOcRemView(*GetOcDoc(), regList, outer);
  323.     else
  324.  
  325.     // By default, our 32-bit container support can 'hold' embedded objects
  326.     // and OCX controls. So we'll default to a 'TOcxView'. However, this
  327.     // can be optimized if the container will never contain any OLE controls.
  328.     //
  329. #if defined(BI_PLAT_WIN32) && !defined(OWL_NO_OCX_CONTAINER_SUPPORT)
  330.       OcView = new TOcxView(*GetOcDoc(), regList, outer);
  331. #elif defined(BI_PLAT_WIN16)
  332.       OcView = new TOcView (*GetOcDoc(), regList, outer);
  333. #endif
  334.  
  335.     Remote = isRemote;
  336.   }
  337.   return OcView;
  338. }
  339.  
  340. //
  341. // Handle the command enabling for a range of command IDs for verbs
  342. //
  343. void
  344. TOleWindow::EvCommandEnable(TCommandEnabler& commandEnabler)
  345. {
  346.   if (CM_EDITFIRSTVERB <= commandEnabler.Id && commandEnabler.Id <= CM_EDITLASTVERB) {
  347.     CeEditVerbs(commandEnabler);
  348.   }
  349.   else if (IsRemote()) {
  350.     // Get the focus, in case it is a child that should receive the cmds
  351.     // fall back to this window in case the Ole menu bar stole focus!
  352.     //
  353.     THandle  hCmdTarget = ::GetFocus();
  354.     if (hCmdTarget != GetHandle() && !IsChild(hCmdTarget))
  355.       hCmdTarget = GetHandle();
  356.  
  357.     RouteCommandEnable(hCmdTarget, commandEnabler);
  358.   }
  359.   else {
  360.     TWindow::EvCommandEnable(commandEnabler);
  361.   }
  362. }
  363.  
  364. //
  365. // processing a range of command IDs for verbs
  366. //
  367. TResult
  368. TOleWindow::EvCommand(uint id, THandle hCtl, uint notifyCode)
  369. {
  370. #if !defined(_OWLDLL)
  371.   TRACEX(OwlCmd, 1, "TOleWindow::EvCommand - id(" << id << "), ctl(" <<\
  372.                      hex << uint(hCtl) << "), code(" << notifyCode  << ")");
  373. #endif
  374.  
  375.   if (hCtl == 0) {
  376.     if (CM_EDITFIRSTVERB <= id && id <= CM_EDITLASTVERB) {
  377.       EvDoVerb(id - CM_EDITFIRSTVERB);
  378.       return 0;
  379.     }
  380.   }
  381.   return TWindow::EvCommand(id, hCtl, notifyCode);
  382. }
  383.  
  384. //
  385. // Intercept CanClose() to interpose OpenEdit semantics. Ole 2 servers don't
  386. // prompt the user on close--just save & close.
  387. //
  388. bool
  389. TOleWindow::CanClose()
  390. {
  391.   // We don't want to close the view for DLL servers
  392.   //
  393.   if (IsOpenEditing() && !OcApp->IsOptionSet(amExeMode)) {
  394.     TOleFrame* olefr = TYPESAFE_DOWNCAST(GetApplication()->GetMainWindow(), TOleFrame);
  395.     CHECK(olefr);
  396.     olefr->ShowWindow(SW_HIDE);
  397.     OleShutDown();
  398.     return false;
  399.   }
  400.  
  401.   if (GetOcRemView() || TWindow::CanClose()) {
  402.     if (OcDoc)
  403.       OcDoc->Close();
  404.     return true;
  405.   }
  406.   return false;
  407. }
  408.  
  409. //
  410. // Notify part
  411. //
  412. void
  413. TOleWindow::InvalidatePart(TOcInvalidate invalid)
  414. {
  415.   if (GetOcRemView())
  416.     GetOcRemView()->Invalidate(invalid);
  417. }
  418.  
  419. //
  420. // Is the window in Open-Edit mode
  421. //
  422. bool
  423. TOleWindow::IsOpenEditing() const
  424. {
  425.   TOcRemView* ocRemView = const_cast<TOleWindow*>(this)->GetOcRemView();
  426.   return ocRemView && ocRemView->GetState() == TOcRemView::OpenEditing;
  427. }
  428.  
  429. //
  430. //
  431. //
  432. TOcPart*
  433. TOleWindow::InsertObject(TOcInitInfo& initInfo, TRect* pos)
  434. {
  435.   TRect rect;
  436.  
  437.   // Pass size request on if caller does not specify
  438.   //
  439.   if (!pos) {
  440.     pos = ▭
  441.     GetInsertPosition(*pos);
  442.   }
  443.  
  444.   TOcPart* part;
  445.   try {
  446.     part = new TOcPart (*GetOcDoc());
  447.     part->Init(&initInfo, *pos);
  448.     SetSelection(part);
  449.     OcView->Rename();
  450.     InvalidatePart(invView);
  451.   }
  452.   catch (TXOle& xole) {
  453.     return 0;
  454.   }
  455.   return part;
  456. }
  457.  
  458. //
  459. //
  460. //
  461. TOcPart*          
  462. TOleWindow::InsertObject(CLSID& objIID, TRect* pos)
  463. {
  464.   TOcInitInfo initInfo(OcView);
  465.  
  466.   // Initialize InitInfo structure
  467.   //
  468.   initInfo.CId   = (BCID) &objIID;    // Object's GUID
  469.   initInfo.Where = iwNew;             // Flag it's a new embedding
  470.   initInfo.How   = ihEmbed;           // Want embedded
  471.  
  472.   return InsertObject(initInfo, pos);
  473. }
  474.  
  475. //
  476. //
  477. //
  478. TOcPart*          
  479. TOleWindow::InsertObject(TString& objProgId, TRect* pos)
  480. {
  481.   // Get IID of OCX from specified ProgID
  482.   //
  483.   CLSID objIID = CLSID_NULL;
  484.   HRESULT hr = ::CLSIDFromProgID(objProgId, &objIID);
  485.  
  486.   if (FAILED(hr)) {
  487.     return 0;
  488.   }
  489.   return InsertObject(objIID, pos);
  490. }
  491.  
  492. #if defined(BI_PLAT_WIN32)
  493.  
  494. //
  495. //
  496. //
  497. TOcControl*
  498. TOleWindow::InsertControl(TOcInitInfo& initInfo, TRect* pos, int id)
  499. {
  500.   TRect rect;
  501.  
  502.   // Pass size request on if caller does not specify
  503.   //
  504.   if (!pos) {
  505.     pos = ▭
  506.     GetInsertPosition(*pos);
  507.   }
  508.  
  509.   // If user did not specify the size (i.e. right & bottom), use
  510.   // some default values...
  511.   //
  512.   if (pos->left == pos->right)
  513.     pos->right = pos->left + 100;
  514.   if (pos->top == pos->bottom)
  515.     pos->bottom = pos->top + 100;
  516.  
  517.   TOcControl* ctrl;
  518.   try {
  519.     ctrl = new TOcControl (*GetOcDoc());
  520.     ctrl->Init(&initInfo, *pos);
  521.     SetSelection(ctrl);
  522.     OcView->Rename();
  523.     InvalidatePart(invView);
  524.     ctrl->SetId(id);
  525.   }
  526.   catch (TXOle& xole) {
  527.     return 0;
  528.   }
  529.   return ctrl;
  530. }
  531.  
  532. //
  533. //
  534. //
  535. TOcControl*
  536. TOleWindow::InsertControl(CLSID& ocxIID, TRect* pos, int id)
  537. {
  538.   TOcInitInfo initInfo(OcView);
  539.  
  540.   // Initialize InitInfo structure
  541.   //
  542.   initInfo.CId   = (BCID) &ocxIID;    // OCX's GUID
  543.   initInfo.Where = iwNewOcx;          // Flag it's an OCX
  544.   initInfo.How   = ihEmbed;           // Want embedded
  545.  
  546.   return InsertControl(initInfo, pos, id);
  547. }
  548.  
  549. //
  550. //
  551. //
  552. TOcControl*
  553. TOleWindow::InsertControl(const TString& ocxProgID, TRect* pos, int id)
  554. {
  555.   // Get IID of OCX from specified ProgID
  556.   //
  557.   CLSID ocxIID = CLSID_NULL;
  558.   HRESULT hr = ::CLSIDFromProgID(ocxProgID, &ocxIID);
  559.  
  560.   if (FAILED(hr)) {
  561.     return 0;
  562.   }
  563.   return InsertControl(ocxIID, pos, id);
  564. }
  565.  
  566.  
  567. //
  568. //
  569. //
  570. TOcControl*
  571. TOleWindow::GetOcControlOfOCX(CLSID ocxIID, uint id)
  572. {
  573.   // Iterate through all parts of this window
  574.   //
  575.   for (TOcPartCollectionIter i(GetOcDoc()->GetParts()); i; i++) {
  576.     TOcPart* p = i.Current();
  577.  
  578.     // NOTE: Here we'll simply dynamic_cast the TOcPart pointer to a
  579.     //       TOcControl. A more OLEish approach would be to querry for
  580.     //       a control interface [IBControl for example] as a safety
  581.     //       measure first.
  582.     //
  583.     TOcControl* pCtrl = TYPESAFE_DOWNCAST(p, TOcControl);
  584.     if (pCtrl) {
  585.       IOleObject* pOleObject = 0;
  586.       if (SUCCEEDED(pCtrl->QueryServer(IID_IOleObject, (void**)&pOleObject))) {
  587.  
  588.         CLSID userClsId;
  589.         if (SUCCEEDED(pOleObject->GetUserClassID(&userClsId)) &&
  590.                       userClsId == ocxIID) {
  591.           if (pCtrl->GetId() == id) {                        
  592.             pOleObject->Release();
  593.             return pCtrl;
  594.           }
  595.         }
  596.         pOleObject->Release();
  597.       }
  598.     }
  599.   }
  600.  
  601.   // Control proxy was not found
  602.   //
  603.   return 0;
  604. }
  605.  
  606. #endif
  607.  
  608. //
  609. // Handles the file File>Close menu option for server app
  610. //
  611. void
  612. TOleWindow::CeFileClose(TCommandEnabler& ce)
  613. {
  614.   // if open editing server, reflect the container's name in "close" option
  615.   //
  616.   if (IsOpenEditing() && GetOcRemView() && GetOcRemView()->GetKind() != TOcRemView::Link) {
  617.     char strCloseMenu[128];
  618.     string optName = GetModule()->LoadString(IDS_CLOSESERVER);
  619.     TString title = GetOcRemView()->GetContainerTitle();
  620.     if (title.Length() > 0) {
  621.       strcpy(strCloseMenu, optName.c_str());
  622.       strcat(strCloseMenu, title);
  623.       //const char far* str = title;
  624.       //optName += str;
  625.     }
  626.     //ce.SetText(optName.c_str());
  627.     ce.SetText(strCloseMenu);
  628.   }
  629. }
  630.  
  631. //
  632. //
  633. //
  634. void
  635. TOleWindow::CeEditInsertObject(TCommandEnabler& ce)
  636. {
  637.   ce.Enable(OcApp && OcView);
  638. }
  639.  
  640. #if defined(BI_PLAT_WIN32)
  641. //
  642. //
  643. //
  644. void
  645. TOleWindow::CeEditInsertControl(TCommandEnabler& ce)
  646. {
  647.   ce.Enable(OcApp && OcView);
  648. }
  649. #endif
  650.  
  651. //
  652. // Get the insertion point for the embedded object in device units.
  653. // Currently we're using only the top left point for position, size is
  654. // redundant.
  655. //
  656. void
  657. TOleWindow::GetInsertPosition(TRect& rect)
  658. {
  659.   TOleClientDC dc(*this);
  660.  
  661.   // Default insertion point is at 0.5" away from current viewport origin
  662.   //
  663.   rect.left  = dc.GetDeviceCaps(LOGPIXELSX) / 2;  // in pixels
  664.   rect.top = dc.GetDeviceCaps(LOGPIXELSY) / 2;    // in pixels
  665.  
  666.   // Adjust the position of embedded object to be in pixels and reflect the
  667.   // zoom factor.
  668.   //
  669.   dc.LPtoDP((TPoint*)&rect, 1);
  670.  
  671.   // No size yet.
  672.   //
  673.   rect.right = rect.left;
  674.   rect.bottom = rect.top;
  675. }
  676.  
  677. //
  678. // Insert an OLE object into the view
  679. //
  680. void
  681. TOleWindow::CmEditInsertObject()
  682. {
  683.   PRECONDITION(OcView);
  684.   TOcInitInfo initInfo(OcView);
  685.  
  686.   if (OcApp->Browse(initInfo)) {
  687.     InsertObject(initInfo);
  688.   }
  689. }
  690.  
  691. #if defined(BI_PLAT_WIN32)
  692. //
  693. // Insert an OLE object into the view
  694. //
  695. void
  696. TOleWindow::CmEditInsertControl()
  697. {
  698.   PRECONDITION(OcView);
  699.   TOcInitInfo initInfo(OcView);
  700.  
  701.   if (OcApp->BrowseControls(initInfo)) {
  702.     InsertControl(initInfo);
  703.   }
  704. }
  705. #endif
  706.  
  707. //
  708. //
  709. //
  710. void
  711. TOleWindow::CeEditDelete(TCommandEnabler& ce)
  712. {
  713.   ce.Enable(DragPart != 0);
  714. }
  715.  
  716. //
  717. //
  718. //
  719. void
  720. TOleWindow::CmEditDelete()
  721. {
  722.   if (!DragPart)
  723.     return;
  724.  
  725.   TOcPartChangeInfo changeInfo(DragPart, TOcInvalidate(invData | invView));
  726.   EvOcViewPartInvalid(changeInfo);
  727.  
  728.   DragPart->Delete();
  729.   DragPart = 0;
  730. }
  731.  
  732. //
  733. //
  734. //
  735. void
  736. TOleWindow::CeEditCut(TCommandEnabler& ce)
  737. {
  738.   ce.Enable(DragPart != 0);
  739. }
  740.  
  741. //
  742. //
  743. //
  744. void
  745. TOleWindow::CmEditCut()
  746. {
  747.   DragPart->Detach();
  748.   OcApp->Copy(DragPart);
  749.   SetSelection(0);
  750. }
  751.  
  752. //
  753. //
  754. //
  755. void
  756. TOleWindow::CeEditCopy(TCommandEnabler& ce)
  757. {
  758.   ce.Enable(DragPart != 0);
  759. }
  760.  
  761. //
  762. //
  763. //
  764. void
  765. TOleWindow::CmEditCopy()
  766. {
  767.   if (DragPart)
  768.     OcApp->Copy(DragPart);
  769. }
  770.  
  771. //
  772. //
  773. //
  774. void
  775. TOleWindow::CeEditPasteLink(TCommandEnabler& ce)
  776. {
  777.   PRECONDITION(OcApp && OcView);
  778.   ce.Enable(OcApp->EnableEditMenu(meEnablePasteLink, OcView));
  779. }
  780.  
  781. //
  782. //
  783. //
  784. void
  785. TOleWindow::CmEditPasteLink()
  786. {
  787.    OcView->Paste(true);
  788. }
  789.  
  790. //
  791. //
  792. //
  793. void
  794. TOleWindow::CeEditPaste(TCommandEnabler& ce)
  795. {
  796.   PRECONDITION(OcApp && OcView);
  797.   ce.Enable(OcApp->EnableEditMenu(meEnablePaste, OcView));
  798. }
  799.  
  800. //
  801. //
  802. //
  803. void
  804. TOleWindow::CmEditPaste()
  805. {
  806.    OcView->Paste(false);
  807.    InvalidatePart(invView);
  808. }
  809.  
  810. //
  811. //
  812. //
  813. void
  814. TOleWindow::CeEditPasteSpecial(TCommandEnabler& ce)
  815. {
  816.   PRECONDITION(OcApp && OcView);
  817.   ce.Enable(OcApp->EnableEditMenu(meEnableBrowseClipboard, OcView));
  818. }
  819.  
  820. //
  821. //
  822. //
  823. void
  824. TOleWindow::CmEditPasteSpecial()
  825. {
  826.   TOcInitInfo initInfo(GetOcView());
  827.  
  828.   if (GetOcView()->BrowseClipboard(initInfo)) {
  829.     if (!OcView->PasteNative(initInfo)) { // Not native data
  830.       EvOcViewPasteObject(initInfo);
  831.     }
  832.     InvalidatePart(invView);
  833.   }
  834. }
  835.  
  836. //
  837. // Append the object menu and enable it
  838. //
  839. void
  840. TOleWindow::CeEditObject(TCommandEnabler& ce)
  841. {
  842.   // Downcast to get at submenu item
  843.   //
  844.   TMenuItemEnabler* me = TYPESAFE_DOWNCAST(&ce, TMenuItemEnabler);
  845.   if (!me)
  846.     return;
  847.  
  848.   int verbPos = me->GetPosition(); // remember the verb menu position
  849.   TMenu editMenu(me->GetMenu());
  850.  
  851.   string optName = GetModule()->LoadString(IDS_EDITOBJECT);
  852.   if (!DragPart) {
  853.     // Remove the verb menu, if any
  854.     //
  855.     if (editMenu.GetSubMenu(verbPos)) {
  856.       editMenu.DeleteMenu(verbPos, MF_BYPOSITION);
  857.       editMenu.InsertMenu(verbPos, MF_GRAYED | MF_BYPOSITION | MF_STRING,
  858.             CM_EDITOBJECT, optName.c_str());
  859.     }
  860.     ce.Enable(false);
  861.     return;
  862.   }
  863.  
  864.   // Add verb menu
  865.   //
  866.   TOcVerb ocVerb;
  867.   TMenu* verbMenu = CreateVerbPopup(ocVerb);
  868.   string newMenuName(OleStr(ocVerb.TypeName));
  869.   newMenuName += ' ';
  870.   newMenuName += optName;
  871.   editMenu.ModifyMenu(verbPos, MF_ENABLED | MF_BYPOSITION | MF_POPUP,
  872.                       (uint)verbMenu->GetHandle(), newMenuName.c_str());
  873.   delete verbMenu;
  874.   ce.Enable(true);
  875. }
  876.  
  877. //
  878. // Command enabler for "Edit" "Convert..." option
  879. //
  880. void
  881. TOleWindow::CeEditConvert(TCommandEnabler& ce)
  882. {
  883.   ce.Enable(DragPart != 0);
  884. }
  885.  
  886. void
  887. TOleWindow::CmEditConvert()
  888. {
  889.   OcApp->Convert(DragPart, false);
  890. }
  891.  
  892. //
  893. // Command enabler for "Edit" "Links..." option
  894. //
  895. void
  896. TOleWindow::CeEditLinks(TCommandEnabler& ce)
  897. {
  898.   PRECONDITION(OcApp && OcView);
  899.   ce.Enable(OcApp->EnableEditMenu(meEnableBrowseLinks, OcView));
  900. }
  901.  
  902. //
  903. //
  904. //
  905. void
  906. TOleWindow::CmEditLinks()
  907. {
  908.   PRECONDITION(OcView);
  909.   OcView->BrowseLinks();
  910. }
  911.  
  912. //
  913. //
  914. //
  915. void
  916. TOleWindow::CeEditVerbs(TCommandEnabler& ce)
  917. {
  918.   ce.Enable(DragPart != 0);
  919. }
  920.  
  921. //
  922. //
  923. //
  924. void
  925. TOleWindow::CmEditShowObjects()
  926. {
  927.   ShowObjects = !ShowObjects;
  928.   Invalidate();
  929. }
  930.  
  931. //
  932. //
  933. //
  934. void
  935. TOleWindow::CeEditShowObjects(TCommandEnabler& ce)
  936. {
  937.   ce.SetCheck(ShowObjects ? TCommandEnabler::Checked : TCommandEnabler::Unchecked);
  938. }
  939.  
  940. //
  941. // Has in-place active part?
  942. //
  943. bool
  944. TOleWindow::HasActivePart()
  945. {
  946.   return OcView->GetActivePart() != 0;
  947. }
  948.  
  949. //
  950. // Change cursor shape if within an embedded object
  951. //
  952. bool
  953. TOleWindow::EvSetCursor(THandle hWnd, uint hitTest, uint mouseMsg)
  954. {
  955.   TPoint pt;
  956.   GetCursorPos(pt);
  957.   ScreenToClient(pt);
  958.   TOcPart* p = OcView->GetActivePart();
  959.  
  960.   if (hitTest == HTCLIENT) {
  961.     if (p) {   // there is an activated part
  962.       TUIHandle handle(p->GetRect(), TUIHandle::Framed);
  963.       if (handle.HitTest(pt) == TUIHandle::MidCenter) {
  964.         return false; // let the inplace server set its cursor shape
  965.       }
  966.       else {   // use arrow cursor
  967.         ::SetCursor(::LoadCursor(0, IDC_ARROW));
  968.         return true;
  969.       }
  970.     }
  971.   }
  972.  
  973.   // Set cursor for resize when cursor over inactive part
  974.   //
  975.   if (!p && DragPart) {
  976.     TRect rect(DragPart->GetRect());
  977.     TOleClientDC dc(*this);
  978.     dc.LPtoDP((TPoint*)&rect, 2);
  979.  
  980.     TUIHandle handle(rect, TUIHandle::HandlesIn | TUIHandle::Grapples |
  981.                      TUIHandle::Framed);
  982.  
  983.     if (handle.HitTest(pt) != TUIHandle::Outside)
  984.       ::SetCursor(::LoadCursor(0, TResId(handle.GetCursorId(handle.HitTest(pt)))));
  985.     else
  986.       ::SetCursor(::LoadCursor(0, IDC_ARROW));
  987.  
  988.     return true;
  989.   }
  990.  
  991.   return ShowCursor(hWnd, hitTest, mouseMsg);
  992. }
  993.  
  994. //
  995. // Show cursor when it's not in an embedded object
  996. //
  997. bool
  998. TOleWindow::ShowCursor(THandle /*hWnd*/, uint /*hitTest*/, uint /*mouseMsg*/)
  999. {
  1000.   ::SetCursor(::LoadCursor(0, IDC_ARROW));
  1001.   return true;
  1002. }
  1003.  
  1004. //
  1005. // Find out if drag and drop needs to be started
  1006. //
  1007. bool
  1008. TOleWindow::StartDrag(uint modKeys, TPoint& point)
  1009. {
  1010.     #if !defined(BI_PLAT_WIN32)
  1011.       static TSize DblClkDelta(3, 3);
  1012.     #else
  1013.       static TSize DblClkDelta(TUIMetric::CxDoubleClk/2,
  1014.                         TUIMetric::CyDoubleClk/2);
  1015.     #endif
  1016.  
  1017.   // no part no drag
  1018.     if (!DragPart)
  1019.       return false;
  1020.  
  1021.   // maybe it was a double click
  1022.     if (abs(point.x-DragStart.x) <= DblClkDelta.cx ||
  1023.                   abs(point.y-DragStart.y) <= DblClkDelta.cy)
  1024.       return false;
  1025.  
  1026.   // start drag and drop anyway if outside client area
  1027.   if (!InClient(*DragDC, point))
  1028.       return true;
  1029.  
  1030.   // start if ctrl or ctrl-shift is pressed but not if alt since move inside client area
  1031.   // doesn't really make sense (a move is a move don't bother ole for that)
  1032.     if ((modKeys & MK_CONTROL))
  1033.       return true;
  1034.  
  1035.   return false;
  1036. }
  1037.  
  1038. //
  1039. // Accept dropped file from file manager
  1040. //
  1041. void
  1042. TOleWindow::EvDropFiles(TDropInfo dropInfo)
  1043. {
  1044.   int fileCount = dropInfo.DragQueryFileCount();
  1045.   for (int index = 0; index < fileCount; index++) {
  1046.     int fileLength = dropInfo.DragQueryFileNameLen(index)+1;
  1047.     OLECHAR* filePath = new OLECHAR[fileLength];
  1048.     dropInfo.DragQueryFile(index, OleStr(filePath), fileLength);
  1049.  
  1050.     TOcInitInfo initInfo(ihEmbed, iwFile, OcView);
  1051.     initInfo.Path = filePath;
  1052.  
  1053.     TRect rect;
  1054.     GetInsertPosition(rect);
  1055.     TOcPart* part = new TOcPart (*GetOcDoc());
  1056.     part->Init(&initInfo, rect);
  1057.     SetSelection(part);
  1058.  
  1059.     OcView->Rename();
  1060.     InvalidatePart(invView);
  1061.  
  1062.     delete[] filePath;
  1063.   }
  1064.   dropInfo.DragFinish();
  1065. }
  1066.  
  1067. //
  1068. // Handle left double-click message
  1069. //
  1070. void
  1071. TOleWindow::EvLButtonDblClk(uint modKeys, TPoint& point)
  1072. {
  1073.   PRECONDITION(GetOcDoc() && GetOcView());
  1074.   TOleClientDC dc(*this);
  1075.   dc.DPtoLP(&point);
  1076.  
  1077.   TOcPart* p = GetOcDoc()->GetParts().Locate(point);
  1078.  
  1079.   if (modKeys & MK_CONTROL) {
  1080.     if (p)
  1081.       p->Open(true);  // Ctrl key forces open editing
  1082.   }
  1083.   else {
  1084.     SetSelection(p);
  1085.  
  1086.     if (p && p == GetOcView()->GetActivePart()) { // resync the active flag
  1087.       p->Activate(false);
  1088.     }
  1089.  
  1090.     GetOcView()->ActivatePart(p); // In-place activation
  1091.   }
  1092. }
  1093.  
  1094. //
  1095. // Set new selection, clear/set handles around objects
  1096. //
  1097. void
  1098. TOleWindow::SetSelection(TOcPart* part)
  1099. {
  1100.   if (part == DragPart)
  1101.     return;
  1102.  
  1103.   // Invalidate old part
  1104.   //
  1105.   TOcPartChangeInfo changeInfo(DragPart, invView);
  1106.   if (DragPart) {
  1107.     DragPart->Select(false);
  1108.     DragPart->Activate(false);
  1109.     EvOcViewPartInvalid(changeInfo);
  1110.   }
  1111.  
  1112.   DragPart = part;
  1113.   changeInfo.SetPart(DragPart);
  1114.   if (DragPart) {
  1115.     part->Select(true); // select this one
  1116.     EvOcViewPartInvalid(changeInfo);
  1117.   }
  1118. }
  1119.  
  1120. //
  1121. // Create popup menu
  1122. //
  1123. void
  1124. TOleWindow::EvRButtonDown(uint, TPoint& point)
  1125. {
  1126.   PRECONDITION(GetOcDoc());
  1127.  
  1128.   // Perform hit test on parts...
  1129.   //
  1130.   TPoint oldPoint = point;
  1131.   TOleClientDC dc(*this);
  1132.   dc.DPtoLP(&point);
  1133.  
  1134.   TOcPart* p = GetOcDoc()->GetParts().Locate(point);
  1135.   SetSelection(p);
  1136.  
  1137.   if (DragPart) {
  1138.     // Create popup menu
  1139.     //
  1140.     TMenu menu(GetModule()->LoadMenu(IDM_OLEPOPUP), AutoDelete);
  1141.     TPopupMenu popMenu(menu.GetSubMenu(0));
  1142.  
  1143.     if (popMenu.GetHandle()) {
  1144.       TOcVerb ocVerb;
  1145.       TMenu* verbMenu = CreateVerbPopup(ocVerb);
  1146.  
  1147.       string optName = GetModule()->LoadString(IDS_EDITOBJECT);
  1148.       string newMenuName(OleStr(ocVerb.TypeName));
  1149.       newMenuName += ' ';
  1150.       newMenuName += optName;
  1151.       popMenu.ModifyMenu(CM_EDITOBJECT, MF_ENABLED | MF_BYCOMMAND | MF_POPUP,
  1152.                          (uint)verbMenu->GetHandle(), newMenuName.c_str());
  1153.       delete verbMenu;
  1154.  
  1155.       // Add the verb menu
  1156.       //
  1157.       ClientToScreen(oldPoint);
  1158.  
  1159.       // Route commands through main window
  1160.       //
  1161.       popMenu.TrackPopupMenu(TPM_RIGHTBUTTON, oldPoint, 0, *this);
  1162.     }
  1163.   }
  1164. }
  1165.  
  1166. //
  1167. // Deactivate active embedded object if any
  1168. //
  1169. bool
  1170. TOleWindow::Deactivate()
  1171. {
  1172.   // Deactivate active part, if any
  1173.   //
  1174.   if (DragPart && DragPart->IsActive()) {
  1175.     SetSelection(0);
  1176.     return true;
  1177.   }
  1178.   else
  1179.     return false;
  1180. }
  1181.  
  1182. //
  1183. // Select embedded object, point is in logical units
  1184. //
  1185. bool
  1186. TOleWindow::Select(uint, TPoint& point)
  1187. {
  1188.   PRECONDITION(GetOcDoc());
  1189.  
  1190.   // If the point is not on the current selection, perform hit test on parts
  1191.   // to find & select one
  1192.   //
  1193.   if (!DragPart || !DragPart->IsVisible(TRect(point, TSize(1,1))))
  1194.     SetSelection(GetOcDoc()->GetParts().Locate(point));
  1195.  
  1196.   // If a part is now selected, manipulate it.
  1197.   //
  1198.   if (DragPart) {
  1199.     DragRect = DragPart->GetRect();
  1200.     DragRect.right++;
  1201.     DragRect.bottom++;
  1202.     if (DragPart->IsSelected()) {
  1203.       TUIHandle handle(DragRect, TUIHandle::HandlesIn | TUIHandle::Grapples |
  1204.                        TUIHandle::Framed);
  1205.       DragHit = handle.HitTest(point);
  1206.     }
  1207.     else {
  1208.       DragHit = TUIHandle::MidCenter;
  1209.     }
  1210.  
  1211.     if (!DragDC)
  1212.       DragDC = new TOleClientDC(*this);
  1213.     DragDC->DrawFocusRect(DragRect);
  1214.  
  1215.     DragStart = DragPt = point;
  1216.     SetCapture();
  1217.  
  1218.     return true;
  1219.   }
  1220.  
  1221.   return false;
  1222. }
  1223.  
  1224. //
  1225. // Check if any embedded object is selected
  1226. //
  1227. void
  1228. TOleWindow::EvLButtonDown(uint modKeys, TPoint& point)
  1229. {
  1230.   // Deactivating in-place active object, if any
  1231.   //
  1232.   if (Deactivate())
  1233.     return;
  1234.  
  1235.   // Convert the point to logical unit
  1236.   //
  1237.   if (!DragDC)
  1238.     DragDC = new TOleClientDC(*this);
  1239.  
  1240.   DragDC->DPtoLP(&point);
  1241.   Select(modKeys, point);
  1242. }
  1243.  
  1244. //
  1245. // Is the logical point within the client area?
  1246. //
  1247. bool
  1248. TOleWindow::InClient(TDC& dc, TPoint& point)
  1249. {
  1250.   TRect logicalRect = GetClientRect();
  1251.  
  1252.   dc.DPtoLP((TPoint*)&logicalRect, 2);
  1253.   return logicalRect.Contains(point);
  1254. }
  1255.  
  1256. //
  1257. //
  1258. //
  1259. void
  1260. TOleWindow::EvMouseMove(uint modKeys, TPoint& point)
  1261. {
  1262.   if (!DragDC)
  1263.     return;
  1264.  
  1265.   // Convert the point to logical unit
  1266.   //
  1267.   DragDC->DPtoLP(&point);
  1268.  
  1269.   // A MidCenter hit is a move
  1270.   //
  1271.   if (DragHit == TUIHandle::MidCenter) {
  1272.     DragDC->DrawFocusRect(DragRect);   // erase old rect
  1273.  
  1274.         // check if initiate drag and drop
  1275.     if (StartDrag(modKeys, point)) {
  1276.       TOcDropAction outAction;
  1277.       OcApp->Drag(DragPart, TOcDropAction(daDropCopy | daDropMove | daDropLink),
  1278.                   outAction);
  1279.  
  1280.       TOcPartChangeInfo changeInfo(DragPart, TOcInvalidate(invView | invData));
  1281.       EvOcViewPartInvalid(changeInfo);
  1282.       DragHit = TUIHandle::Outside;
  1283.       ReleaseCapture();
  1284.  
  1285.       // Delete the dragged part since it was dragged out
  1286.       //
  1287.       if (outAction == daDropMove) {
  1288.         DragPart->Delete();
  1289.         DragPart = 0;
  1290.       }
  1291.     }
  1292.     else {
  1293.       TPoint delta = point - DragPt;
  1294.       DragRect.Offset(delta.x, delta.y);
  1295.       DragDC->DrawFocusRect(DragRect);   // draw new rect
  1296.     }
  1297.   }
  1298.   // All other non-outside hits are resizes
  1299.   //
  1300.   else if (DragHit != TUIHandle::Outside) { // handle
  1301.     DragDC->DrawFocusRect(DragRect);   // erase old rect
  1302.     int dl = (DragHit%3) == 0 ? point.x - DragPt.x : 0;
  1303.     int dr = (DragHit%3) == 2 ? point.x - DragPt.x : 0;
  1304.     int dt = (DragHit/3) == 0 ? point.y - DragPt.y : 0;
  1305.     int db = (DragHit/3) == 2 ? point.y - DragPt.y : 0;
  1306.  
  1307.     // maintain minimum part size
  1308.     //
  1309.     if ((DragRect.Width() + dr - dl) >= MinWidth) {
  1310.       DragRect.left += dl;
  1311.       DragRect.right += dr;
  1312.     }
  1313.     if ((DragRect.Height() + db - dt) >= MinHeight) {
  1314.       DragRect.top  += dt;
  1315.       DragRect.bottom += db;
  1316.     }
  1317.  
  1318.     DragDC->DrawFocusRect(DragRect);   // draw new rect
  1319.   }
  1320.  
  1321.   DragPt = point;
  1322. }
  1323.  
  1324. //
  1325. //
  1326. //
  1327. void
  1328. TOleWindow::EvLButtonUp(uint /*modKeys*/, TPoint& /*point*/)
  1329. {
  1330.   if (DragPart) {
  1331.     TOcPartChangeInfo changeInfo(DragPart, TOcInvalidate(invView | invData));
  1332.  
  1333.     // All non-outside hits are moves or resizes
  1334.     //
  1335.     if (DragHit != TUIHandle::Outside) {
  1336.       EvOcViewPartInvalid(changeInfo);
  1337.       DragPart->SetPos(DragRect.TopLeft());
  1338.       if (DragHit != TUIHandle::MidCenter)
  1339.         DragPart->SetSize(DragRect.Size());  // A MidCenter hit is a move only
  1340.       EvOcViewPartInvalid(changeInfo);
  1341.     }
  1342.     InvalidatePart(invView);
  1343.  
  1344.     DragHit = TUIHandle::Outside;
  1345.     ReleaseCapture();
  1346.   }
  1347.  
  1348.   if (DragDC) {
  1349.     delete DragDC;
  1350.     DragDC = 0;
  1351.     DragRect.SetNull();
  1352.   }
  1353. }
  1354.  
  1355. //
  1356. // Let OcView know that the view window has changed sizes
  1357. //
  1358. void
  1359. TOleWindow::EvSize(uint sizeType, TSize& size)
  1360. {
  1361.   TWindow::EvSize(sizeType, size);
  1362.   OcView->EvResize();
  1363. }
  1364.  
  1365. //
  1366. // Handle message forwarded from our mdi child frame (if any) to let OcView
  1367. // know that the view window has changed size
  1368. //
  1369. void
  1370. TOleWindow::EvMDIActivate(THandle hActivated, THandle /*hDeactivated*/)
  1371. {
  1372.   if (OcView)
  1373.     OcView->EvActivate(hActivated == *Parent);
  1374. }
  1375.  
  1376. uint
  1377. TOleWindow::EvMouseActivate(THandle topParent, uint /*hitCode*/, uint /*msg*/)
  1378. {
  1379.   if (topParent)
  1380.     ForwardMessage(topParent);
  1381.  
  1382.   return MA_ACTIVATE;
  1383. }
  1384.  
  1385. //
  1386. // May need to pass focus to an in-place server if there is one
  1387. //
  1388. void
  1389. TOleWindow::EvSetFocus(THandle hLostFocus)
  1390. {
  1391.   TWindow::EvSetFocus(hLostFocus);
  1392.   if (OcView)
  1393.     OcView->EvSetFocus(true); // Maybe active part (if any) wants focus
  1394. }
  1395.  
  1396. //
  1397. // response method for an incoming WM_VSCROLL message
  1398. //
  1399. void
  1400. TOleWindow::EvHScroll(uint scrollCode, uint thumbPos, THandle hCtl)
  1401. {
  1402.   TWindow::EvHScroll(scrollCode, thumbPos, hCtl);
  1403.  
  1404.   InvalidatePart(invView);
  1405. }
  1406.  
  1407. //
  1408. // response method for an incoming WM_VSCROLL message
  1409. //
  1410. void
  1411. TOleWindow::EvVScroll(uint scrollCode, uint thumbPos, THandle hCtl)
  1412. {
  1413.   TWindow::EvVScroll(scrollCode, thumbPos, hCtl);
  1414.  
  1415.   InvalidatePart(invView);
  1416. }
  1417.  
  1418. //
  1419. // Handle WM_MENUSELECT to provide hint text in the container's status bar
  1420. // based on the menu item id. Treat popup items separatly and ask them for
  1421. // their ids. Similar to code in TDecoratedFrame.
  1422. //
  1423. void
  1424. TOleWindow::EvMenuSelect(uint menuItemId, uint flags, HMENU hMenu)
  1425. {
  1426.   if (GetOcRemView()) {
  1427.     if (flags == 0xFFFF && hMenu == 0) {  // menu closing
  1428.       GetOcRemView()->SetContainerStatusText("");
  1429.       return;
  1430.     }
  1431.     else if (flags & MF_POPUP) {
  1432.       TMenu popupMenu(hMenu);
  1433.       int   count = popupMenu.GetMenuItemCount();
  1434.       int   pos = 0;
  1435.       for (;pos < count && popupMenu.GetSubMenu(pos) != HMENU(menuItemId);
  1436.             pos++)
  1437.         ;
  1438.       menuItemId = popupMenu.GetMenuItemID(pos);
  1439.     }
  1440.     else if (flags & (MF_SEPARATOR | MF_MENUBREAK | MF_MENUBARBREAK)
  1441.       || (menuItemId >= IDW_FIRSTMDICHILD && menuItemId < IDW_FIRSTMDICHILD+9)) {
  1442.       menuItemId = 0;  // display an empty help message
  1443.     }
  1444.     string text = GetModule()->LoadString(menuItemId);
  1445.     GetOcRemView()->SetContainerStatusText(text.c_str());
  1446.   }
  1447.   else
  1448.     TWindow::EvMenuSelect(menuItemId, flags, hMenu);
  1449. }
  1450.  
  1451. //
  1452. // Handle & sub-dispatch the OC event message.
  1453. //
  1454. TResult
  1455. TOleWindow::EvOcEvent(TParam1 param1, TParam2 param2)
  1456. {
  1457.   TEventHandler::TEventInfo eventInfo(WM_OCEVENT, param1);
  1458.   if (Find(eventInfo))
  1459.     return Dispatch(eventInfo, param1, param2);
  1460.   return 0;
  1461. }
  1462.  
  1463. //
  1464. // Return our frame's title
  1465. //
  1466. const char far*
  1467. TOleWindow::EvOcViewTitle()
  1468. {
  1469.   char title[128];
  1470.   Parent->GetWindowText(title, sizeof title);
  1471.   ContainerName = title;
  1472.  
  1473.   return ContainerName.c_str();
  1474. }
  1475.  
  1476. //
  1477. // Set our frame's title
  1478. //
  1479. void
  1480. TOleWindow::EvOcViewSetTitle(const char far* title)
  1481. {
  1482.   if (title && *title)
  1483.     Parent->SetWindowText(title);
  1484.   else if (GetOcRemView() && GetOcRemView()->GetKind() == TOcRemView::Link) {
  1485.     const char far* caption = GetFileName();
  1486.     if (caption)
  1487.       Parent->SetWindowText(caption);
  1488.   }
  1489. }
  1490.  
  1491. //
  1492. // Can the server put toolbars in our view? Say no--make him use the app frame
  1493. //
  1494. bool
  1495. TOleWindow::EvOcViewBorderSpaceReq(TRect far* /*space*/)
  1496. {
  1497.   return false;
  1498. }
  1499.  
  1500. //
  1501. // Can the server put toolbars in our view? Say no--make him use the app frame
  1502. //
  1503. bool
  1504. TOleWindow::EvOcViewBorderSpaceSet(TRect far* /*space*/)
  1505. {
  1506.   return false;
  1507. }
  1508.  
  1509. //
  1510. // Can the indicated ole object be dropped here? Say yes to everything as a
  1511. // default
  1512. //
  1513. bool
  1514. TOleWindow::EvOcViewDrop(TOcDragDrop far& /*ddInfo*/)
  1515. {
  1516.   return true;    // ok to drop anything, we can take it...
  1517. }
  1518.  
  1519. //
  1520. // Provide drag UI feedback
  1521. //
  1522. bool
  1523. TOleWindow::EvOcViewDrag(TOcDragDrop far& ddInfo)
  1524. {
  1525.   TClientDC dc(*this);
  1526.   TPen pen(TColor(128, 128, 128), 4, PS_DOT);
  1527.   dc.SelectObject(pen);
  1528.   dc.SelectStockObject(HOLLOW_BRUSH);
  1529.   dc.SetROP2(R2_NOTXORPEN);
  1530.  
  1531.   dc.Rectangle(*ddInfo.Pos);
  1532.   return true;
  1533. }
  1534.  
  1535. //
  1536. // Scroll our view window. Update any internal state as needed. This is called
  1537. // when the server is sizing, or a drop interaction is near the edge
  1538. //
  1539. bool
  1540. TOleWindow::EvOcViewScroll(TOcScrollDir /*scrollDir*/)
  1541. {
  1542.   return false;
  1543. }
  1544.  
  1545. //
  1546. // Convert the part rect into device units
  1547. //
  1548. bool
  1549. TOleWindow::EvOcViewGetSiteRect(TRect far* rect)
  1550. {
  1551.   TOleClientDC dc(*this);
  1552.  
  1553.   return dc.LPtoDP((TPoint*)rect, 2);
  1554. }
  1555.  
  1556. //
  1557. // Convert the part rect into logical units
  1558. //
  1559. bool
  1560. TOleWindow::EvOcViewSetSiteRect(TRect far* rect)
  1561. {
  1562.   TOleClientDC dc(*this);
  1563.  
  1564.   return dc.DPtoLP((TPoint*)rect, 2);
  1565. }
  1566.  
  1567. //
  1568. // Handle the scaling for server app
  1569. //
  1570. bool
  1571. TOleWindow::EvOcViewGetScale(TOcScaleFactor& scaleFactor)
  1572. {
  1573.   scaleFactor = Scale;
  1574.   return true;
  1575. }
  1576.  
  1577. //
  1578. // Handle the scaling for server app
  1579. //
  1580. bool
  1581. TOleWindow::EvOcViewPartActivate(TOcPart& ocPart)
  1582. {
  1583.   SetSelection(&ocPart);
  1584.   return true;
  1585. }
  1586.  
  1587. //
  1588. // Handle the scaling for server app
  1589. //
  1590. bool
  1591. TOleWindow::EvOcViewPasteObject(TOcInitInfo& init)
  1592. {
  1593.   TRect rect;
  1594.   GetInsertPosition(rect);
  1595.   TOcPart* part = new TOcPart (*GetOcDoc());
  1596.   part->Init(&init, rect);
  1597.   init.ReleaseDataObject();
  1598.   return true;
  1599. }
  1600.  
  1601. //
  1602. // Ask server to paint itself in the position and dc provided
  1603. //
  1604. bool
  1605. TOleWindow::EvOcViewPaint(TOcViewPaint far& vp)
  1606. {
  1607.   // Paint according to the view paint structure
  1608.   //
  1609.   TDC dc(vp.DC);
  1610.   Pos = *vp.Pos;
  1611.  
  1612.   // Paint embedded objects
  1613.   //
  1614.  
  1615.   bool metafile = dc.GetDeviceCaps(TECHNOLOGY) == DT_METAFILE;
  1616.   SetupDC(dc, !metafile);
  1617.  
  1618.   if (vp.Moniker) {
  1619.     PaintLink(dc, true, Pos, *vp.Moniker);
  1620.   }
  1621.   else if (vp.PaintSelection) {
  1622.     PaintSelection(dc, true, Pos, vp.UserData);
  1623.   }
  1624.   else {
  1625.     Paint(dc, true, Pos);
  1626.     PaintParts(dc, true, Pos, metafile);
  1627.   }
  1628.  
  1629.   Pos.SetNull();
  1630.  
  1631.   return true;
  1632. }
  1633.  
  1634. //
  1635. // TOcRemView is going away, disconnect TOleWindow with it so we don't use it
  1636. // later. If this is a remote view, then close the doc too.
  1637. //
  1638. bool
  1639. TOleWindow::EvOcViewClose()
  1640. {
  1641.   if (IsRemote() && OcDoc)
  1642.     OcDoc->Close();
  1643.  
  1644.   OcView = 0;
  1645.   return true;
  1646. }
  1647.  
  1648. //
  1649. // Ask server to save itself in the IStorage
  1650. //
  1651. bool
  1652. TOleWindow::EvOcViewSavePart(TOcSaveLoad far& /*ocSave*/)
  1653. {
  1654.   return true;
  1655. }
  1656.  
  1657. //
  1658. // Ask server to load itself from the IStorage
  1659. //
  1660. bool
  1661. TOleWindow::EvOcViewLoadPart(TOcSaveLoad far& /*ocLoad*/)
  1662. {
  1663.   return true;
  1664. }
  1665.  
  1666. //
  1667. // Let container know about the server view size in pixels
  1668. //
  1669. bool
  1670. TOleWindow::EvOcViewPartSize(TOcPartSize far& /*size*/)
  1671. {
  1672.   return false;
  1673. }
  1674.  
  1675. //
  1676. // Ask container to open an existing document
  1677. // Used for linking from embedding
  1678. //
  1679. bool
  1680. TOleWindow::EvOcViewOpenDoc(const char far* /*path*/)
  1681. {
  1682.   return true;
  1683. }
  1684.  
  1685. //
  1686. // Insert server menu into the composite one
  1687. //
  1688. bool
  1689. TOleWindow::EvOcViewInsMenus(TOcMenuDescr far& /*sharedMenu*/)
  1690. {
  1691.   return false;
  1692. }
  1693.  
  1694. //
  1695. // Request for server to put up its toolbar. This implementation assume that
  1696. // this server is single use, and the MainWindow's ToolBar is ours to snarf
  1697. //
  1698. bool
  1699. TOleWindow::EvOcViewShowTools(TOcToolBarInfo far& tbi)
  1700. {
  1701.   TWindow* mainWindow = GetApplication()->GetMainWindow();
  1702.   CHECK(mainWindow);
  1703.   TWindow* toolBar = mainWindow->ChildWithId(IDW_TOOLBAR);
  1704.   if (!toolBar)
  1705.     return false;
  1706.   tbi.HTopTB = THandle(*toolBar);
  1707.   return true;
  1708. }
  1709.  
  1710. //
  1711. // Get server's color palette
  1712. //
  1713. bool
  1714. TOleWindow::EvOcViewGetPalette(LOGPALETTE far* far* /*palette*/)
  1715. {
  1716.   return false;
  1717. }
  1718.  
  1719. //
  1720. // Ask server to provide data according to the format in a handle
  1721. //
  1722. bool
  1723. TOleWindow::EvOcViewClipData(TOcFormatData far& /*format*/)
  1724. {
  1725.   return false;
  1726. }
  1727.  
  1728. //
  1729. // Set format data into server
  1730. //
  1731. bool
  1732. TOleWindow::EvOcViewSetData(TOcFormatData far& /*format*/)
  1733. {
  1734.   return false;
  1735. }
  1736.  
  1737. #if defined(BI_PLAT_WIN32)
  1738. //
  1739. // Get Ambient properties
  1740. //
  1741. bool
  1742. TOleWindow::EvOcAmbientGetBackColor(long* /*backColor*/)
  1743. {
  1744.   return false;
  1745. }
  1746.  
  1747. bool
  1748. TOleWindow::EvOcAmbientGetForeColor(long* /*foreColor*/)
  1749. {
  1750.   return false;
  1751. }
  1752.  
  1753. bool
  1754. TOleWindow::EvOcAmbientGetLocaleID(long* /*localeId*/)
  1755. {
  1756.   return false;
  1757. }
  1758.  
  1759. bool
  1760. TOleWindow::EvOcAmbientGetTextAlign(short* /*align*/)
  1761. {
  1762.   return false;
  1763. }
  1764.  
  1765. bool
  1766. TOleWindow::EvOcAmbientGetMessageReflect(bool* /*reflectMessage*/)
  1767. {
  1768.   return false;
  1769. }
  1770.  
  1771. bool
  1772. TOleWindow::EvOcAmbientGetUserMode(bool* /*userMode*/)
  1773. {
  1774.   return false;
  1775. }
  1776.  
  1777. bool
  1778. TOleWindow::EvOcAmbientGetUIDead(bool* /*deadUI*/)
  1779. {
  1780.   return false;
  1781. }
  1782.  
  1783. bool
  1784. TOleWindow::EvOcAmbientGetShowGrabHandles(bool* /*showGrabHandles*/)
  1785. {
  1786.   return false;
  1787. }
  1788.  
  1789. bool
  1790. TOleWindow::EvOcAmbientGetShowHatching(bool* /*showHatching*/)
  1791. {
  1792.   return false;
  1793. }
  1794.  
  1795. bool
  1796. TOleWindow::EvOcAmbientGetDisplayAsDefault(bool* /*displayAsDefault*/)
  1797. {
  1798.   return false;
  1799. }
  1800.  
  1801. bool
  1802. TOleWindow::EvOcAmbientGetSupportsMnemonics(bool* /*supportMnemonics*/)
  1803. {
  1804.   return false;
  1805. }
  1806.  
  1807. bool
  1808. TOleWindow::EvOcAmbientGetDisplayName(TString** /*name*/)
  1809. {
  1810.   return false;
  1811. }
  1812.  
  1813. bool
  1814. TOleWindow::EvOcAmbientGetScaleUnits(TString** /*units*/)
  1815. {
  1816.   return false;
  1817. }
  1818.  
  1819. bool
  1820. TOleWindow::EvOcAmbientGetFont(IDispatch** /*font*/)
  1821. {
  1822.   return false;
  1823. }
  1824.  
  1825. bool
  1826. TOleWindow::EvOcAmbientSetBackColor(long /*backColor*/)
  1827. {
  1828.   return false;
  1829. }
  1830.  
  1831. bool
  1832. TOleWindow::EvOcAmbientSetForeColor(long /*foreColor*/)
  1833. {
  1834.   return false;
  1835. }
  1836.  
  1837. bool
  1838. TOleWindow::EvOcAmbientSetLocaleID(long /*localeId*/)
  1839. {
  1840.   return false;
  1841. }
  1842.  
  1843. bool
  1844. TOleWindow::EvOcAmbientSetTextAlign(short /*align*/)
  1845. {
  1846.   return false;
  1847. }
  1848.  
  1849. bool
  1850. TOleWindow::EvOcAmbientSetMessageReflect(bool /*reflect*/)
  1851. {
  1852.   return false;
  1853. }
  1854.  
  1855. bool
  1856. TOleWindow::EvOcAmbientSetUserMode(bool /*userMode*/)
  1857. {
  1858.   return false;
  1859. }
  1860.  
  1861. bool
  1862. TOleWindow::EvOcAmbientSetUIDead(bool /*dead*/)
  1863. {
  1864.   return false;
  1865. }
  1866.  
  1867. bool
  1868. TOleWindow::EvOcAmbientSetShowGrabHandles(bool /*showHandles*/)
  1869. {
  1870.   return false;
  1871. }
  1872.  
  1873. bool
  1874. TOleWindow::EvOcAmbientSetShowHatching(bool /*showHatching*/)
  1875. {
  1876.   return false;
  1877. }
  1878.  
  1879. bool
  1880. TOleWindow::EvOcAmbientSetDisplayAsDefault(bool /*displayAsDefault*/)
  1881. {
  1882.   return false;
  1883. }
  1884.  
  1885. bool
  1886. TOleWindow::EvOcAmbientSetSupportsMnemonics(bool /*supportMnemonics*/)
  1887. {
  1888.   return false;
  1889. }
  1890.  
  1891. bool
  1892. TOleWindow::EvOcAmbientSetDisplayName(TString* /*name*/)
  1893. {
  1894.   return false;
  1895. }
  1896.  
  1897. bool
  1898. TOleWindow::EvOcAmbientSetScaleUnits(TString* /*units*/)
  1899. {
  1900.   return false;
  1901. }
  1902.  
  1903. bool
  1904. TOleWindow::EvOcAmbientSetFont(IDispatch* /*font*/)
  1905. {
  1906.   return false;
  1907. }
  1908.  
  1909. //
  1910. // Control Event Dispatches
  1911. //
  1912. bool
  1913. TOleWindow::EvOcCtrlClick(TCtrlEvent* /*pev*/)
  1914. {
  1915.   return false;
  1916. }
  1917.  
  1918. bool
  1919. TOleWindow::EvOcCtrlDblClick(TCtrlEvent* /*pev*/)
  1920. {
  1921.   return false;
  1922. }
  1923.  
  1924. bool
  1925. TOleWindow::EvOcCtrlMouseDown(TCtrlMouseEvent* /*pev*/)
  1926. {
  1927.   return false;
  1928. }
  1929.  
  1930. bool
  1931. TOleWindow::EvOcCtrlMouseUp(TCtrlMouseEvent* /*pev*/)
  1932. {
  1933.   return false;
  1934. }
  1935.  
  1936. bool
  1937. TOleWindow::EvOcCtrlMouseMove(TCtrlMouseEvent* /*pev*/)
  1938. {
  1939.   return false;
  1940. }
  1941.  
  1942. bool
  1943. TOleWindow::EvOcCtrlKeyDown(TCtrlKeyEvent* /*pev*/)
  1944. {
  1945.   return false;
  1946. }
  1947.  
  1948. bool
  1949. TOleWindow::EvOcCtrlKeyUp(TCtrlKeyEvent* /*pev*/)
  1950. {
  1951.   return false;
  1952. }
  1953.  
  1954. bool
  1955. TOleWindow::EvOcCtrlErrorEvent(TCtrlErrorEvent* /*pev*/)
  1956. {
  1957.   return false;
  1958. }
  1959.  
  1960. bool
  1961. TOleWindow::EvOcCtrlFocus(TCtrlFocusEvent* /*pev*/)
  1962. {
  1963.   return false;
  1964. }
  1965.  
  1966. bool
  1967. TOleWindow::EvOcCtrlPropertyChange(TCtrlPropertyEvent* /*pev*/)
  1968. {
  1969.   return false;
  1970. }
  1971.  
  1972. bool
  1973. TOleWindow::EvOcCtrlPropertyRequestEdit(TCtrlPropertyEvent* /*pev*/)
  1974. {
  1975.   return false;
  1976. }
  1977.  
  1978. bool
  1979. TOleWindow::EvOcCtrlCustomEvent(TCtrlCustomEvent* /*pev*/)
  1980. {
  1981.   return false;
  1982. }
  1983. #endif
  1984.  
  1985. //
  1986. // Paint the embedded objects
  1987. //
  1988. bool
  1989. TOleWindow::PaintParts(TDC& dc, bool, TRect&, bool metafile)
  1990. {
  1991.   if (!GetOcDoc())
  1992.     return false;
  1993.  
  1994.   TRect clientRect;
  1995.   TRect logicalRect = GetClientRect();
  1996.  
  1997.   if (IsRemote()) {
  1998.     clientRect = GetWindowRect();
  1999.     clientRect.Offset(-clientRect.left, -clientRect.top);
  2000.   }
  2001.   else {
  2002.     clientRect = logicalRect;
  2003.   }
  2004.  
  2005.   TPoint scrollPos(0, 0);
  2006.  
  2007.   if (!metafile) {
  2008.     dc.DPtoLP((TPoint*)&logicalRect, 2);
  2009.   }
  2010.   else {
  2011.     if (Scroller) {
  2012.       scrollPos.x = (int)Scroller->XPos;
  2013.       scrollPos.y = (int)Scroller->YPos;
  2014.     }
  2015.   }
  2016.  
  2017.   for (TOcPartCollectionIter i(GetOcDoc()->GetParts()); i; i++) {
  2018.     TOcPart& p = *i.Current();
  2019.     if (p.IsVisible(logicalRect) || metafile) {
  2020.       TRect r = p.GetRect();
  2021.       r.Offset(-scrollPos.x, -scrollPos.y);
  2022.       p.Draw(dc, r, clientRect, asDefault);
  2023.  
  2024.       if (metafile)
  2025.         continue;
  2026.  
  2027.       // Paint selection
  2028.       //
  2029.       if ((p.IsSelected() || ShowObjects) && r.Width() > 0 && r.Height() > 0) {
  2030.         uint handleStyle = p.IsLink() ? TUIHandle::DashFramed : TUIHandle::Framed;
  2031.         if (p.IsSelected())
  2032.           handleStyle |= TUIHandle::Grapples;
  2033.         TUIHandle(r, handleStyle).Paint(dc);
  2034.       }
  2035.     }
  2036.   }
  2037.   return true;
  2038. }
  2039.  
  2040. //
  2041. // Change the scaling factor
  2042. //
  2043. void
  2044. TOleWindow::SetScale(uint16 percent)
  2045. {
  2046.   Scale.SetScale(percent);
  2047.   Invalidate();
  2048. }
  2049.  
  2050. //
  2051. // Get the logical unit per inch for document
  2052. //
  2053. void
  2054. TOleWindow::GetLogPerUnit(TSize& logPerUnit)
  2055. {
  2056.   TScreenDC dc;
  2057.  
  2058.   logPerUnit.cx = dc.GetDeviceCaps(LOGPIXELSX);
  2059.   logPerUnit.cy = dc.GetDeviceCaps(LOGPIXELSY);
  2060. }
  2061.  
  2062. //
  2063. // Setup the dc before painting
  2064. //
  2065. void
  2066. TOleWindow::SetupDC(TDC& dc, bool scale)
  2067. {
  2068.   dc.SetMapMode(MM_ANISOTROPIC);
  2069.  
  2070.   // Setup window and viewport origin according to scroll amount
  2071.   //
  2072.   TPoint scrollPos(0, 0);
  2073.   if (Scroller) {
  2074.     scrollPos.x = (int)Scroller->XPos;
  2075.     scrollPos.y = (int)Scroller->YPos;
  2076.   }
  2077.  
  2078.   if (!scale) {
  2079.     dc.SetWindowOrg(scrollPos);
  2080.     return;
  2081.   }
  2082.  
  2083.   // Don't scale the scrolling amount
  2084.   //
  2085.   if (Scale.SiteSize.cx)
  2086.     scrollPos.x = (int)(((uint32)scrollPos.x * Scale.PartSize.cx +
  2087.                         Scale.SiteSize.cx/2) / Scale.SiteSize.cx);
  2088.   if (Scale.SiteSize.cy)
  2089.     scrollPos.y = (int)(((uint32)scrollPos.y * Scale.PartSize.cy +
  2090.                         Scale.SiteSize.cy/2) / Scale.SiteSize.cy);
  2091.   dc.SetWindowOrg(scrollPos);
  2092.  
  2093.   dc.SetViewportOrg(Pos.TopLeft());
  2094.  
  2095.   // set the window and viewport extaccording to zoom factor
  2096.   //
  2097.   TSize ext;
  2098.   GetLogPerUnit(ext);
  2099.   dc.SetWindowExt(ext);
  2100.  
  2101.   ext.cx = dc.GetDeviceCaps(LOGPIXELSX);
  2102.   ext.cy = dc.GetDeviceCaps(LOGPIXELSY);
  2103.  
  2104.   if (Scale.PartSize.cx)
  2105.     ext.cx = (int)(((uint32)ext.cx * Scale.SiteSize.cx + Scale.PartSize.cx/2) /
  2106.                    Scale.PartSize.cx);
  2107.   if (Scale.PartSize.cy)
  2108.     ext.cy = (int)(((uint32)ext.cy * Scale.SiteSize.cy + Scale.PartSize.cy/2) /
  2109.                    Scale.PartSize.cy);
  2110.   dc.SetViewportExt(ext);
  2111. }
  2112.  
  2113. //
  2114. // response method for an incoming WM_PAINT message
  2115. //
  2116. void
  2117. TOleWindow::EvPaint()
  2118. {
  2119.   if (IsFlagSet(wfAlias))
  2120.     DefaultProcessing();  // use application-defined wndproc
  2121.  
  2122.   else {
  2123.     TPaintDC dc(*this);
  2124.     TRect&   rect = *(TRect*)&dc.Ps.rcPaint;
  2125.  
  2126.     if (Scroller)
  2127.       Scroller->BeginView(dc, rect);
  2128.  
  2129.     bool metafile = dc.GetDeviceCaps(TECHNOLOGY) == DT_METAFILE;
  2130.     SetupDC(dc, !metafile);
  2131.     Paint(dc, dc.Ps.fErase, rect);
  2132.     PaintParts(dc, dc.Ps.fErase, rect, metafile);
  2133.  
  2134.     if (Scroller)
  2135.       Scroller->EndView();
  2136.   }
  2137. }
  2138.  
  2139. //
  2140. // Notify the active view of part data changes
  2141. //
  2142. bool
  2143. TOleWindow::EvOcViewPartInvalid(TOcPartChangeInfo& changeInfo)
  2144. {
  2145.   // Our document is now dirty...
  2146.  
  2147.   // Reflect the change in part in other (non-active) views
  2148.   //
  2149.   TRect rect(changeInfo.GetPart()->GetRect());
  2150.   rect.right++;
  2151.   rect.bottom++;
  2152.   TOleClientDC dc(*this);
  2153.   dc.LPtoDP((TPoint*)&rect, 2);
  2154.  
  2155.   InvalidateRect(rect);  // Multiview support to be done in derived classes
  2156.  
  2157.   // Notify container if this is an intermediate container
  2158.   //
  2159.   InvalidatePart((TOcInvalidate)changeInfo.GetType());
  2160.  
  2161.   return true; // stop further processing by OCF
  2162. }
  2163.  
  2164. //
  2165. //
  2166. //
  2167. TPopupMenu*
  2168. TOleWindow::CreateVerbPopup(const TOcVerb& ocVerb)
  2169. {
  2170.   TPopupMenu* verbMenu = new TPopupMenu(NoAutoDelete);
  2171.   while (DragPart->EnumVerbs(ocVerb)) {
  2172.     verbMenu->AppendMenu(MF_STRING|MF_ENABLED,
  2173.                          (uint)CM_EDITFIRSTVERB + ocVerb.VerbIndex,
  2174.                          (const char far*)OleStr(ocVerb.VerbName));
  2175.   }
  2176.  
  2177.   verbMenu->AppendMenu(MF_SEPARATOR, 0, 0);
  2178.   string optName = GetModule()->LoadString(IDS_EDITCONVERT);
  2179.   verbMenu->AppendMenu(MF_STRING, CM_EDITCONVERT, optName.c_str());
  2180.  
  2181.   return verbMenu;
  2182. }
  2183.  
  2184. //
  2185. // Execute a verb pertaining to the selected object
  2186. //
  2187. void
  2188. TOleWindow::EvDoVerb(uint whichVerb)
  2189. {
  2190.   DragPart->DoVerb(whichVerb);
  2191. }
  2192.  
  2193. //
  2194. // Attach this view back to its owl parent for either open editing, or
  2195. // mearly inplace de-activating
  2196. //
  2197. bool
  2198. TOleWindow::EvOcViewAttachWindow(bool attach)
  2199. {
  2200.   TOleFrame* mainWindow = TYPESAFE_DOWNCAST(GetApplication()->GetMainWindow(),
  2201.                                             TOleFrame);
  2202.   if (!mainWindow)
  2203.     return false;  // server app is shutting down
  2204.  
  2205.   if (attach) {
  2206.     if (IsOpenEditing()) {
  2207.       // Derived class needs to managed setting up frame differently, like
  2208.       // for MDI etc.
  2209.       //
  2210.       mainWindow->SetClientWindow(this);
  2211.     }
  2212.   }
  2213.   else {
  2214.     if (IsOpenEditing() && Parent != mainWindow)
  2215.       Parent->PostMessage(WM_CLOSE);
  2216.     SetParent(mainWindow->GetRemViewBucket());  // simple reparent
  2217.   }
  2218.   return true;
  2219. }
  2220.  
  2221. //
  2222. // Perform the action indentified by verb
  2223. //
  2224. bool
  2225. TOleWindow::EvOcViewDoVerb(uint /*verb*/)
  2226. {
  2227.   return false;
  2228. }
  2229.  
  2230. //
  2231. // Perform the action indentified by verb
  2232. //
  2233. bool
  2234. TOleWindow::EvOcViewTransformCoords(uint /*verb*/)
  2235. {
  2236.   return false;
  2237. }
  2238.  
  2239. //
  2240. // Shut down the associated OCF partners if possible
  2241. //
  2242. bool
  2243. TOleWindow::OleShutDown()
  2244. {
  2245.   if (IsRemote()) {
  2246.     TOcRemView* ocRemView = GetOcRemView();
  2247.     if (IsOpenEditing())
  2248.       ocRemView->Disconnect();
  2249.   }
  2250.   else {
  2251.     if (OcView)
  2252.       OcView->EvClose();
  2253.   }
  2254.   return true;
  2255. }
  2256.  
  2257. //
  2258. // Perform normal CleanupWindow, plus let the OcView object know we have closed
  2259. //
  2260. void
  2261. TOleWindow::CleanupWindow()
  2262. {
  2263.   TOleFrame* mainWindow = TYPESAFE_DOWNCAST(GetApplication()->GetMainWindow(),
  2264.                                             TOleFrame);
  2265.   if (mainWindow)
  2266.     mainWindow->OleViewClosing(true);
  2267.   OleShutDown();
  2268.   if (mainWindow)
  2269.     mainWindow->OleViewClosing(false);
  2270.   TWindow::CleanupWindow();
  2271. }
  2272.  
  2273.  
  2274. //
  2275. // TOleWindow processes idle action occurs once per block of messages
  2276. //
  2277. bool
  2278. TOleWindow::IdleAction(long idleCount)
  2279. {
  2280.  
  2281.   return TWindow::IdleAction(idleCount);
  2282. }
  2283.  
  2284. bool
  2285. TOleWindow::PreProcessMsg(MSG& msg)
  2286. {
  2287.   if (TWindow::PreProcessMsg(msg))
  2288.     return true;  // Processed accelerators
  2289.   return false;
  2290. }
  2291.  
  2292. //
  2293. // Handle the scaling for server app
  2294. //
  2295. bool
  2296. TOleWindow::EvOcViewSetScale(TOcScaleFactor& scaleFactor)
  2297. {
  2298.   Scale = scaleFactor;
  2299.   return true;
  2300. }
  2301.  
  2302. //
  2303. // Find the item name for whole doc or selection
  2304. //
  2305. bool
  2306. TOleWindow::EvOcViewGetItemName(TOcItemName& /*item*/)
  2307. {
  2308.   return false;
  2309. }
  2310.  
  2311. //----------------------------------------------------------------------------
  2312. // Linking Spport
  2313. //
  2314.  
  2315. //
  2316. // Establish link with whole doc or selection
  2317. //
  2318. bool
  2319. TOleWindow::EvOcViewSetLink(TOcLinkView& /*view*/)
  2320. {
  2321.   return false;
  2322. }
  2323.  
  2324. //
  2325. // Break link with whole doc or selection
  2326. //
  2327. bool
  2328. TOleWindow::EvOcViewBreakLink(TOcLinkView& /*view*/)
  2329. {
  2330.   return false;
  2331. }
  2332.